package com.yumeng.framework.auth.security.config;

import com.yumeng.framework.auth.security.access.JsonAccessDeniedHandler;
import com.yumeng.framework.auth.security.authentication.JsonAuthenticationEntryPoint;
import com.yumeng.framework.auth.security.authentication.JsonAuthenticationFailureHandler;
import com.yumeng.framework.auth.security.authentication.JwtTokenAuthenticationSuccessHandler;
import com.yumeng.framework.auth.security.logout.JsonLogoutSuccessHandler;
import com.yumeng.framework.auth.security.session.JsonInvalidSessionStrategy;
import com.yumeng.framework.auth.security.session.JsonSessionInformationExpiredStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.security.web.session.InvalidSessionStrategy;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;

/**
 * SpringSecurity配置文件（用于前后端分离）
 *
 *
 * @author wxd
 * @date 2025/2/21 21:12
 */
@Slf4j
public abstract class SecurityConfigurationForJson extends SecurityConfiguration {

    protected boolean isFBS(){
        return true;
    }

    /**
     * 自定义认证入口点【未认证】
     */
    protected AuthenticationEntryPoint getAuthenticationEntryPoint(){
        return new JsonAuthenticationEntryPoint();
    }

    /**
     * 拒绝访问处理器【权限不足】
     *
     * @return
     */
    protected AccessDeniedHandler getAccessDeniedHandler(){
        return new JsonAccessDeniedHandler();
    }

    /**
     * 认证成功处理（会覆盖loginSuccessUrl）【认证成功】
     */
    protected AuthenticationSuccessHandler getAuthenticationSuccessHandler() {
        return new JwtTokenAuthenticationSuccessHandler();
    }

    /**
     * 认证失败处理（会覆盖loginFailureUrl）【认证失败】
     */
    protected AuthenticationFailureHandler getAuthenticationFailureHandler() {
        return new JsonAuthenticationFailureHandler();
    }

    /**
     * 自定义注销成功处理器【注销登录】
     */
    protected LogoutSuccessHandler getLogoutSuccessHandler() {
        return new JsonLogoutSuccessHandler();
    }

    /**
     * 会话超时（失效）策略 （会覆盖InvalidSessionUrl）
     */
    @Override
    protected InvalidSessionStrategy getInvalidSessionStrategy() {
        return new JsonInvalidSessionStrategy();
    }

    /**
     * 会话到期策略（在线踢人）（会覆盖ExpiredSessionUrl）
     */
    @Override
    protected SessionInformationExpiredStrategy getSessionInformationExpiredStrategy() {
        return new JsonSessionInformationExpiredStrategy();
    }

    @Override
    protected boolean enableNormalAuth(){
        return true;
    }

    @Override
    protected boolean enableRequestCache() {
        return false;
    }

/*    @Override
    protected boolean enableAnonymous() {
        return false;
    }*/
}
